package com.example;

import org.openjdk.jol.info.ClassLayout;

/**
 * 演示 无锁 到 轻量级锁
 */
public class HeavyLockDemo {

    public static void main(String[] args) throws InterruptedException {
        System.out.println(Thread.currentThread().getName()+":无锁 --------------------start");
        final Person person = new Person();
        System.out.println(Thread.currentThread().getName()+":hashCode(16进制):"+Integer.toHexString(person.hashCode()));
        System.out.println(ClassLayout.parseInstance(person).toPrintable());
        System.out.println(Thread.currentThread().getName()+":无锁 --------------------end");


        new Thread(new Runnable() {
            public void run() {
                synchronized (person){
                    System.out.println(Thread.currentThread().getName()+": 重量级 --------------------start");
                    System.out.println(Thread.currentThread().getName()+": +hashCode(16进制):"+Integer.toHexString(person.hashCode()));
                    System.out.println(ClassLayout.parseInstance(person).toPrintable());
                    System.out.println(Thread.currentThread().getName()+":重量级 --------------------start");
                }
            }
        }).start();



        new Thread(new Runnable() {
            public void run() {
                synchronized (person){
                    System.out.println(Thread.currentThread().getName()+": 重量级1 --------------------start");
                    System.out.println(Thread.currentThread().getName()+": +hashCode(16进制):"+Integer.toHexString(person.hashCode()));
                    System.out.println(ClassLayout.parseInstance(person).toPrintable());
                    System.out.println(Thread.currentThread().getName()+":重量级1 --------------------start");
                }
            }
        }).start();
    }
}
